package com.cs.cssupplier.controller;

import com.cs.cssupplier.domain.CsDevice;
import com.cs.cssupplier.mapper.CsDeviceMapper;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * @Author：lyj
 * @Package：com.cs.cssupplier.controller
 * @Project：RuoYi-Cloud-master
 * @name：CsDeviceController
 * @Date：2024/12/21 12:37
 * @Filename：CsDeviceController
 */
@RestController
@RequestMapping("/device")
public class CsDeviceController extends BaseController {
    @Autowired
    private CsDeviceMapper csDeviceMapper;

    /**
     * 根据id查询技术人员
     * @param tId
     * @return
     */
    @GetMapping(value = "/{tId}")
    public AjaxResult csDeviceId(@PathVariable("tId") String tId){
        return AjaxResult.success(csDeviceMapper.selectCsDeviceByTid(tId));
    }

    /**
     * 查询所有的技术人员信息
     * @param csDevice
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(CsDevice csDevice){
        startPage();
        List<CsDevice> list=csDeviceMapper.selectCsDeviceList(csDevice);
        return getDataTable(list);
    }

    @GetMapping("/max")
    public ResponseEntity<Map<String, Object>>  maxList(){
        Integer maxTid = csDeviceMapper.selectCsDeviceMaxTid();
        Map<String, Object> response = new HashMap<>();
        response.put("data", maxTid+1);
        return ResponseEntity.ok(response);
    }


    /**
     * 添加技术人员信息
     * @param csDevice
     * @return
     */
    @PostMapping("/deviceNewAdd")
    public AjaxResult insertCsDevice(@RequestBody CsDevice csDevice){
        System.out.println(csDevice.gettId()+"dsdddd");
        return toAjax(csDeviceMapper.insertCsDevice(csDevice));
    }

    /**
     * 修改技术人员信息
     * @param csDevice
     * @return
     */
    @PutMapping("deviceNewUpdate")
    public AjaxResult updateCsDevice(@RequestBody CsDevice csDevice){

        System.out.println(csDeviceMapper.updateCsDevice(csDevice)+"///////");
        return toAjax(csDeviceMapper.updateCsDevice(csDevice));
    }
}
